/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.remotec.handler;

import lombok.SneakyThrows;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts.remotec
 * @author:LiBo/Alex
 * @create-date:2020-04-06 21:20
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class RebotHandler {

    @SneakyThrows
    public static void start() {
        // 创建一个机器人对象
        Robot robot = new Robot();
        //当前屏幕大小
        Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
        Dimension dm = tk.getScreenSize();
        //计算屏幕中心点
        int x = (int) dm.getWidth() / 2;
        int y = (int) dm.getHeight() / 2;
        // 将鼠标移动到屏幕中心
        robot.mouseMove(x, y);
        // 按下鼠标左键
        robot.mousePress(InputEvent.BUTTON1_MASK);
        // 松开鼠标左键
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        // 模拟按下回车键
        robot.keyPress(KeyEvent.VK_ENTER);
        // 模拟放松回车键
        robot.keyRelease(KeyEvent.VK_ENTER);
        // 按下SHIFT键
        robot.keyPress(KeyEvent.VK_SHIFT);
        for (int i = 0; i < 10; i++) {
            // 在屏幕上打字
            robot.keyPress('A'+ i);
            robot.keyRelease('A'+ i);
            Thread.sleep(500);
        }
        // 松开SHIFT键
        robot.keyRelease(KeyEvent.VK_SHIFT);
        for (int i = 0; i < 11; i++) {
            // 删除操作
            robot.keyPress(KeyEvent.VK_BACK_SPACE);
            robot.keyRelease(KeyEvent.VK_BACK_SPACE);
            Thread.sleep(500);
        }
    }

    public static void main(String[] args){
        start();
    }
}
